package com.googlecode.imanager.core.base.style;

import com.googlecode.imanager.client.bridge.style.IStyle;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class ComputedStyle implements IStyle, ComputedAttribute<IStyle> {

    protected ComputedFont font;
    protected ComputedBorder borderLeft;
    protected ComputedBorder borderTop;
    protected ComputedBorder borderRight;
    protected ComputedBorder borderBottom;
    protected ComputedBackground background;
    protected ComputedOpacity opacity;

    public ComputedStyle() {
        font = new ComputedFont();
        borderLeft = new ComputedBorder();
        borderTop = new ComputedBorder();
        borderRight = new ComputedBorder();
        borderBottom = new ComputedBorder();
        background = new ComputedBackground();
        opacity = new ComputedOpacity();
    }
    
    public void mergeWith(IStyle o){
        if (o == null){
            return;
        }
        
        font.mergeWith(o.getFont());
        borderLeft.mergeWith(o.getBorderLeft());
        borderTop.mergeWith(o.getBorderTop());
        borderRight.mergeWith(o.getBorderRight());
        borderBottom.mergeWith(o.getBorderBottom());
        background.mergeWith(o.getBackground());
        opacity.mergeWith(o.getOpacity());        
    }

    @Override
    public void copyFrom(IStyle o) {
        if (o == null){
            font.copyFrom(null);
            borderLeft.copyFrom(null);
            borderTop.copyFrom(null);
            borderRight.copyFrom(null);
            borderBottom.copyFrom(null);
            background.copyFrom(null);
            opacity.copyFrom(null);
        } else {        
            font.copyFrom(o.getFont());
            borderLeft.copyFrom(o.getBorderLeft());
            borderTop.copyFrom(o.getBorderTop());
            borderRight.copyFrom(o.getBorderRight());
            borderBottom.copyFrom(o.getBorderBottom());
            background.copyFrom(o.getBackground());
            opacity.copyFrom(o.getOpacity());
        }
    }

    public ComputedFont getFont() {
        return font;
    }

    public ComputedBorder getBorderLeft() {
        return borderLeft;
    }

    public ComputedBorder getBorderTop() {
        return borderTop;
    }

    public ComputedBorder getBorderRight() {
        return borderRight;
    }

    public ComputedBorder getBorderBottom() {
        return borderBottom;
    }

    public ComputedBackground getBackground() {
        return background;
    }

    public ComputedOpacity getOpacity() {
        return opacity;
    }

}
